﻿using System;
using System.Web.UI;
using mojoPortal.Web.RS.SBM.AppCode.Lib;

 
namespace mojoPortal.Web.RS.SBM
{
    public partial class RSEstimateDetail : RSBasePage
    {
        int _companyid = 0;
        int _estimateid = 0;
        int _location = 0;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

        }

        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                InitializeReadyServicePage("Estimate Detail");
                RSUserIdentity userIdentity = GetRSUserIdentity();
                _companyid = userIdentity.RSCompanyId;

                if (Request.QueryString["estimateid"] != null)
                    _estimateid = Convert.ToInt32(Request.QueryString["Estimateid"].ToString());

                if (_estimateid > 0)
                {
                    _location = RSSBMCommonFunctions.GetLocationIDByEstimateID(_companyid, _estimateid);
                    ucLocationHeaderControl.LoadLocationHeader(_companyid, _location);
                    bool hasData = ucEstimateControl.LoadEstimateDataByID(_companyid, _location, _estimateid);
                    if (hasData)
                    {
                        //ucEstimateTaskListControl.LoadEstimateTaskList(_companyid, _estimateid);
                        //ucEstimatePartListControl.LoadEstimatePartListByID(_companyid, _estimateid);

                        //lblEstimatePart.Text = "Estimate ID: " + _estimateid.ToString();
                        //lblEstimateTask.Text = "Estimate ID: " + _estimateid.ToString();
                    }
                }
            }
        }
        private void ActiveTabChanged(int Estimateid)
        {
            if (Estimateid > 0)
            {
                switch (tcEstimateDetail.ActiveTabIndex)
                {
                    case 0:
                        //Response.Redirect("RSEstimateDetail.aspx?Estimateid=" + Estimateid);
                        break;
                    case 1:
                        Response.Redirect("RSEstimateTasks.aspx?estimateid=" + Estimateid);
                        break;
                    case 2:
                        Response.Redirect("RSEstimateParts.aspx?estimateid=" + Estimateid);
                        break;

                    //default:
                }
            }

        }

        protected void tcEstimateDetail_OnActiveTabChanged(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["estimateid"]))
                _estimateid = Convert.ToInt32(Request.QueryString["estimateid"].ToString());

            ActiveTabChanged(_estimateid);
        }

        //protected void btnAddTask_Click(Object sender, EventArgs e)
        //{
        //    RSUserIdentity userIdentity = GetRSUserIdentity();
        //    if (userIdentity.RSCanWrite)
        //    {
        //        Response.Redirect("~/RS/SBM/RSManageEstimateTask.aspx?action=add&Estimateid=" + _Estimateid);
        //    }
        //    else
        //        ucModalActionMessageControl.ShowModal("You Do Not Have Permission To Perform This Action!", "", false);
        //}

        //protected void btnAddParts_Click(Object sender, EventArgs e)
        //{
        //    RSUserIdentity userIdentity = GetRSUserIdentity();
        //    if (userIdentity.RSCanWrite)
        //    {
        //        Response.Redirect("~/RS/SBM/RSShoppingPart.aspx?isEstimate=1&action=add&Estimateid=" + _Estimateid);
        //    }
        //    else
        //        ucModalActionMessageControl.ShowModal("You Do Not Have Permission To Perform This Action!", "", false);
            
        //}
    }
}